package weblab.tutor;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import phonegap.ex.R;
import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

public class QuizActivity extends Activity{
	
	public void onCreate(Bundle savedInstanceState){		
		super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        String lesson_id = getIntent().getStringExtra("lesson_id");

        WebView wv = (WebView) findViewById(R.id.webView);
		wv.getSettings().setJavaScriptEnabled(true);
		wv.setWebChromeClient(new WebChromeClient());
		
		String line = "", text = "";
		try{
			AssetManager assetManager = getAssets(); 
			BufferedReader br = new BufferedReader(new InputStreamReader(assetManager.open("www/questions.html")));
    		while((line = br.readLine()) != null)
    			text += line + "\n";
    	}
    	catch(Exception e){
    		e.printStackTrace();
    	}
    	
		wv.loadUrl("file:///android_asset/www/quizScreen.html");
		wv.addJavascriptInterface(new WebQuizInterface(this,lesson_id,text), "Android");
	}
}